+function ($) {
    "use strict";
    var page, defaults = {
        onSuccess: undefined
    }
    function debounce(fn, interval) {
        let timer = null; // 定时器
        return function () {
            // 清除上一次的定时器
            clearTimeout(timer);
            // 拿到当前的函数作用域
            let _this = this;
            // 拿到当前函数的参数数组
            let args = Array.prototype.slice.call(arguments, 0);
            // 开启倒计时定时器
            timer = setTimeout(function () {
                // 通过apply传递当前函数this，以及参数
                fn.apply(_this, args);
                // 默认300ms执行
            }, interval || 300)
        }
    }
    $.fn.lobsterreachbottom = function (params) {
        return this.each(function () {
            params = $.extend({}, defaults, params);
            page = $(this);
            page.scroll(
                debounce(
                    function () {
                        let pageHeight = Math.max(document.body.scrollHeight, document.body.offsetHeight);
                        let viewportHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight || 0;
                        let scrollHeight = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
                        if (pageHeight - viewportHeight - scrollHeight < 50) {
                            params.onSuccess && typeof params.onSuccess == "function" && params.onSuccess();
                        }
                    }), 1000);
        })
    };
}($);